// ============================================================================
//  gPawnAccuracy.uc ::
// ============================================================================
class gPawnAccuracy extends Object
    within gPawn;


var() float                 InaccuracyAir;          // in air
var() float                 InaccuracySprint;       // on ground, sprinting
var() float                 InaccuracyWalk;         // on ground, walking
var() float                 InaccuracyStand;        // on ground, not moving
var() float                 InaccuracyCrouch;       // on ground, crouching
var() float                 InaccuracyCrouchIdle;   // on ground, crouching but not moving
var() float                 InaccuracySwim;         // in water
var() float                 InaccuracySwimIdle;     // in water but not moving

var() float                 InaccuracyBaseYaw;      // Bob strength, 8192 = 90 degrees
var() float                 InaccuracyBasePitch;    //
var() float                 InaccuracyMultYaw;      // Bob speed
var() float                 InaccuracyMultPitch;    //

var   float                 InaccuracyTimeYaw;
var   float                 InaccuracyTimePitch;
var   float                 InaccuracyTimeLast;

final simulated function float GetStanceSpread()
{
    local bool bIdle;

    bIdle = Acceleration == vect(0,0,0) && VSize(Velocity) < 20;

    if( Physics == PHYS_Walking )
    {
        if( bIdle )
        {
            if( bIsCrouched )   return InaccuracyCrouchIdle;
            else                return InaccuracyStand;
        }
        else if( bIsCrouched )  return InaccuracyCrouch;
        else if( bIsWalking )   return InaccuracyWalk;
        else                    return InaccuracySprint;
    }
    else if( Physics == PHYS_Falling )
    {
        return FMax(InaccuracyWalk, InaccuracyAir*FMin(1,(Abs(Velocity.Z) / JumpZ)) );
    }
    else if( Physics == PHYS_Swimming )
    {
        if( bIdle ) return InaccuracySwimIdle;
        else        return InaccuracySwim;
    }

    return 0;
}


final simulated function rotator GetBobSpread()
{
    local rotator BobRot;
    local float DT, Alpha;

//    BobRot.Pitch = sin( Level.TimeSeconds * pi ) * 1024;
//    BobRot.Yaw = cos( Level.TimeSeconds * pi ) * 1024;
//    return BobRot;

    //Alpha = VSize(Velocity)/default.GroundSpeed;
    Alpha = GetStanceSpread();

    DT = Level.TimeSeconds - InaccuracyTimeLast;
    InaccuracyTimeLast = Level.TimeSeconds;

    InaccuracyTimeYaw += DT * Alpha;
    InaccuracyTimePitch = InaccuracyTimeYaw;

    BobRot.Pitch = sin( InaccuracyTimePitch * InaccuracyMultPitch ) * InaccuracyBasePitch * Alpha;
    BobRot.Yaw = sin( InaccuracyTimeYaw * InaccuracyMultYaw ) * InaccuracyBaseYaw * Alpha;

    return BobRot;
}

defaultproperties
{
     InaccuracyAir=0.850000
     InaccuracySprint=1.000000
     InaccuracyWalk=0.500000
     InaccuracyStand=0.050000
     InaccuracyCrouch=0.050000
     InaccuracySwim=0.250000
     InaccuracySwimIdle=0.100000
     InaccuracyBaseYaw=640.000000
     InaccuracyBasePitch=640.000000
     InaccuracyMultYaw=6.000000
     InaccuracyMultPitch=14.750000
}
